﻿using System.Linq;

namespace Cms.Domain
{
    public class PermissionChecker
    {
        private readonly Administrator _admin;

        public PermissionChecker(Administrator admin)
        {
            _admin = admin;
        }

        public bool ConfigureFirstSite
        {
            get { return GetPermission("ConfigureFirstSite"); }
        }

        public bool Explorer
        {
            get { return GetPermission("Explorer"); }
        }

        public bool ExplorerAddFolder
        {
            get { return GetPermission("ExplorerAddFolder"); }
        }

        public bool Sites
        {
            get { return GetPermission("Sites"); }
        }

        public bool PublishContent
        {
            get { return GetPermission("PublishContent"); }
        }

        public bool UserGroups
        {
            get { return GetPermission("UserGroups"); }
        }

        public bool Administrators
        {
            get { return GetPermission("Administrators"); }
        }

        public bool AdministratorGroups
        {
            get { return GetPermission("AdministratorGroups"); }
        }

        public bool Plugins
        {
            get { return GetPermission("Plugins"); }
        }

        public bool PluginTemplates
        {
            get { return GetPermission("PluginTemplates"); }
        }

        public bool EditPluginTemplate
        {
            get { return GetPermission("EditPluginTemplate"); }
        }

        public bool EditPluginTemplateLiterals
        {
            get { return GetPermission("EditPluginTemplateLiterals"); }
        }

        public bool Comments
        {
            get { return GetPermission("Comments"); }
        }

        public bool EditUserGroup
        {
            get { return GetPermission("EditUserGroup"); }
        }

        public bool Categories
        {
            get { return GetPermission("Categories"); }
        }

        public bool EditCategory
        {
            get { return GetPermission("EditCategory"); }
        }

        public bool EditAdministrator
        {
            get { return GetPermission("EditAdministrator"); }
        }

        public bool EditAdministratorGroup
        {
            get { return GetPermission("EditAdministratorGroup"); }
        }

        public bool CustomAdminPages
        {
            get { return GetPermission("CustomAdminPages"); }
        }

        public bool EditCustomAdminPage
        {
            get { return GetPermission("EditCustomAdminPage"); }
        }

        public bool EditFolder
        {
            get { return GetPermission("EditFolder"); }
        }

        public bool EditPage
        {
            get { return GetPermission("EditPage"); }
        }

        public bool EditApplicationPage
        {
            get { return GetPermission("EditApplicationPage"); }
        }

        public bool Stylesheets
        {
            get { return GetPermission("Stylesheets"); }
        }

        public bool EditStylesheet
        {
            get { return GetPermission("EditStylesheet"); }
        }

        public bool Update
        {
            get { return GetPermission("Update"); }
        }

        public bool Locales
        {
            get { return GetPermission("Locales"); }
        }

        public bool EditLocale
        {
            get { return GetPermission("EditLocale"); }
        }

        public bool DashboardGadgets
        {
            get { return GetPermission("DashboardGadgets"); }
        }

        public bool EditSite
        {
            get { return GetPermission("EditSite"); }
        }

        public bool MasterTemplates
        {
            get { return GetPermission("MasterTemplates"); }
        }

        public bool EditMasterTemplate
        {
            get { return GetPermission("EditMasterTemplate"); }
        }

        public bool DetailTemplates
        {
            get { return GetPermission("DetailTemplates"); }
        }

        public bool EditDetailTemplate
        {
            get { return GetPermission("EditDetailTemplate"); }
        }

        public bool Applications
        {
            get { return GetPermission("Applications"); }
        }

        public bool EditApplication
        {
            get { return GetPermission("EditApplication"); }
        }

        public bool ApplicationPages
        {
            get { return GetPermission("ApplicationPages"); }
        }

        public bool SearchContent
        {
            get { return GetPermission("SearchContent"); }
        }

        public bool EditContent
        {
            get { return GetPermission("EditContent"); }
        }

        public bool EditCustomDashboardGadget
        {
            get { return GetPermission("EditCustomDashboardGadget"); }
        }

        public bool Menus
        {
            get { return GetPermission("Menus"); }
        }

        public bool EditMenu
        {
            get { return GetPermission("EditMenu"); }
        }

        public bool EditMenuItem
        {
            get { return GetPermission("EditMenuItem"); }
        }

        public bool Media
        {
            get { return GetPermission("Media"); }
        }

        public bool EditMediaFolder
        {
            get { return GetPermission("EditMediaFolder"); }
        }

        public bool EditMediaFile
        {
            get { return GetPermission("EditMediaFile"); }
        }

        public bool Upload
        {
            get { return GetPermission("Upload"); }
        }

        public bool EditContentPreview
        {
            get { return GetPermission("EditContentPreview"); }
        }

        public bool Users
        {
            get { return GetPermission("Users"); }
        }

        public bool EditUser
        {
            get { return GetPermission("EditUser"); }
        }

        public bool AddUser
        {
            get { return GetPermission("AddUser"); }
        }

        public bool RssFeeds
        {
            get { return GetPermission("RssFeeds"); }
        }

        public bool AddRssFeed
        {
            get { return GetPermission("AddRssFeed"); }
        }

        public bool EditRssFeed
        {
            get { return GetPermission("EditRssFeed"); }
        }

        public bool DeleteRssFeed
        {
            get { return GetPermission("DeleteRssFeed"); }
        }

        public bool CustomizeEditor
        {
            get { return GetPermission("CustomizeEditor"); }
        }

        private bool GetPermission(string permissionName)
        {
            if (_admin.Group == null)
                return false;
            if (_admin.Group.ID == 1)
                return true;
            return _admin.Group.Permissions.FirstOrDefault(p => p.Name == permissionName) != null;
        }
    }
}